<?php

class contributionsController extends baseController {

    public function index() {

        if ($this->registry->session->loggedin) {

            header('location: /contributions/login');

        } else {

            // Set a template variable
            $this->registry->template->welcome = 'Please Log In';
            $this->registry->template->message = '';

            $this->registry->template->show('index');

        }

    }

    public function login() {

        $this->registry->template->welcome = 'Your details';

        if ($this->registry->session->loggedin) {

            $this->registry->template->message = 'Thank you for being logged in';

        } else {

            if ($this->auth = new RayAuth($this->registry, $_POST['username'], $_POST['password']) != false) {

                $this->registry->template->message = 'You have successfully logged in, thank you!';

            } else {

                $this->registry->template->message = 'You have failed to log in!';

            }

        }

        $this->registry->template->show('logged');

    }
    
    public function add() {
    	
    	$this->registry->template->welcome = "Add Contribution";
    	
    	$this->registry->template->message = "";
    	
    	$this->registry->template->show('logged');
    	
    }
    
    public function logout() {
    	
    	$this->registry->session->destroy('loggedin');
    	
    	header('location: /contributions');
    	
    }

}

?>
